
<?php
$saveOrder = ($ordering=='ordering');
?>
<?= formOpen(site_url('admin/category/index'), 'post', 'id="adminForm" class="formAjax"') ?>
	<div class="table-responsive">
		<table class="table table-hover table-striped" id="tableList">
			<thead>
				<tr>
					<th width="1%" class="text-center nowrap"><?= lang('status') ?></th>
					<th><?= lang('title') ?></th>
					<th><?= lang('menu_parent') ?></th>
					<th width="1%" class="text-center nowrap"><?= lang('id') ?></th>
					<th width="1%" class="text-center nowrap"><span class="sr-only"><?= lang('delete') ?></span></th>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<td colspan="9" class="text-center">
					</td>
				</tr>
			</tfoot>
			<tbody class="sortable">
			<?php $order = array();
			foreach($items as $k=>$item): 
				$order[] = $item->ordering; ?>
				<tr data-id="<?= $item->id ?>">
					<td width="1%" class="text-center">
						<a href="<?= site_url('admin/menu/toggle/published/'.$item->id.'/'.(1-$item->published)) ?>" class="btn btn-default btn-micro hasTip toggle linkAjax" title="<?= lang('toggle_to_publish') ?>"><i class="icon-<?php if(!$item->published) echo 'un' ?>publish"></i></a>
					</td>
					<td><?= anchor(site_url('admin/menu/form/'.$item->id), $item->title) ?></td>
					<td><?php if($item->parent) echo $item->parent->title ?></td>
					<td width="1%" class="text-center"><?= $item->id ?></td>
					<td width="1%" class="text-center">
						<a href="<?= site_url('admin/menu/delete/'.$item->id) ?>" class="btn btn-default btn-micro hasTip linkAjax" title="<?= lang('delete_this') ?>" data-confirm="<?= lang('sure_delete_this') ?>"><i class="icon-trash"></i></a>
					</td>
				</tr>
			<?php endforeach ?>
			</tbody>
		</table>
	</div>
	<div id="data-ordering" data-ordering="<?= implode(',',$order); ?>"></div>
<?= formClose() ?>

<script type="text/javascript">

/* when the DOM is ready */
$(document).ready(function(){
	$('tbody.sortable').sortable({
		handle: '>.sortable-handler',
		opacity: 0.7,
		update: function(){
			var data_order = $('#data-ordering').data('ordering');
			var data_id = $(this).sortable('toArray',{ attribute: 'data-id'});
			console.log(data_order);
			console.log(data_id.join(','));
		}
	});
});
</script>
